package org.example;

import java.util.*;

public class immutable_Demo1 {
    public static void main(String[] args) {
        //创建不可变集合
        List<String> list=List.of("a","b","c");
        //list.add("d");不可添加 不可添加
        System.out.println(list);
        System.out.println("===============");
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println("===============");
        Iterator<String> it=list.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("===============");
        Set<String> set=Set.of("a","b","c");
        //set集合里没有索引，不能使用get方法
        //set集合没有add方法
        //set集合没有remove方法
        //set集合没有clear方法
        System.out.println(set);
        System.out.println("===============");
        for (String s : set) {
            System.out.println(s);
        }
        System.out.println("===============");
        Iterator<String> it1=set.iterator();
        while(it1.hasNext()){
            System.out.println(it1.next());
        }
        System.out.println("===============");
        Map<String,String> map=Map.of("A","a","B","b","C","c");
        System.out.println(map);
        Set<String> key= map.keySet();
        for (String s : key) {
            String value=map.get(s);
            System.out.println(value);
        }
        System.out.println("===============");
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String key1 = entry.getKey();
            String value1 = entry.getValue();
            System.out.println(key1+value1);
        }

    }
}
